home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / infosrvr / dev / www_talk.930 / 000181_connolly@pixel.convex.com _Thu Jul 16 05:50:02 1992.msg < prev    next >
Internet Message Format  |  1994-01-24  |  2KB

  1. Return-Path: <connolly@pixel.convex.com>
  2. Received: from dxmint.cern.ch by  nxoc01.cern.ch  (NeXT-1.0 (From Sendmail 5.52)/NeXT-2.0)
  3.     id AA05332; Thu, 16 Jul 92 05:50:02 MET DST
  4. Received: by dxmint.cern.ch (dxcern) (5.57/3.14)
  5.     id AA05889; Thu, 16 Jul 92 05:49:45 +0200
  6. Received: from pixel.convex.com by convex.convex.com (5.64/1.35)
  7.     id AA25548; Wed, 15 Jul 92 22:49:23 -0500
  8. Received: from localhost by pixel.convex.com (5.64/1.28)
  9.     id AA25229; Wed, 15 Jul 92 22:49:22 -0500
  10. Message-Id: <9207160349.AA25229@pixel.convex.com>
  11. To: www-talk@nxoc01.cern.ch
  12. Subject: perl script to legalize HTML files
  13. Date: Wed, 15 Jul 92 22:49:21 CDT
  14. From: Dan Connolly <connolly@pixel.convex.com>
  15.  
  16. #!/usr/local/bin/perl
  17. #
  18. # USE
  19. #   fix-html.pl <W3-file.html >W3-file.sgml
  20. #
  21. # SEE ALSO
  22. #   the html.dtd.
  23. #
  24.  
  25. print "<!DOCTYPE HTML SYSTEM>\n";
  26.  
  27. @html = <>;            # read whole file
  28. $_ = join('', @html);
  29.  
  30. while(/</){
  31.     &out($`);
  32.     $_ = $';
  33.     if(s/^A\s+//i){
  34.     &fix_anchor;
  35.     }elsif(s/^NEXTID\s+(\d+)\s*>//){
  36.     &out("<NEXTID N=$1>");
  37.     }else{
  38.     &out('<');
  39.     }
  40. }
  41.  
  42. &out($_);
  43.  
  44. sub out{
  45.     print $_[0];
  46. }
  47.  
  48. sub fix_anchor{
  49.     local($name, $href, $type);
  50.  
  51.     # What exactly is the syntax of an SGML attribute value?
  52.     while(s/^(\w+)\s*=\s*((\"[^\"]*\")|([^\s>]+))\s*//){
  53.     local($v) = ($3 || $4);
  54.     local($a) = $1;
  55.     $href = $v if $a =~ /^href$/i;
  56.     $name = $v if $a =~ /^name$/i;
  57.     $type = $v if $a =~ /^type$/i;
  58.     }
  59.     s/[^>]*>//;
  60.  
  61.     &out("<A");
  62.     &out(" NAME=\"$name\"") if $name ne '';
  63.     &out(" TYPE=\"$type\"") if $type ne '';
  64.     &out(" HREF=\"$href\"") if $href ne '';
  65.     &out(">");
  66. }